﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CY.Utility.Common
{
    public static class ParseUtility
    {
        public static bool TryParseInt32(string s, out int result)
        {
            return Int32.TryParse(s, out result);
        }

        public static bool TryParseInt32(string s, System.Globalization.NumberStyles styles, IFormatProvider provider, out int result)
        {
            return Int32.TryParse(s, styles, provider, out result);
        }

        public static bool TryParseInt64(string s, out long result)
        {
            return Int64.TryParse(s, out result);
        }

        public static bool TryParseInt32(string s, System.Globalization.NumberStyles styles, IFormatProvider provider, out long result)
        {
            return Int64.TryParse(s, styles, provider, out result);
        }

        public static bool TryParseDateTime(string s, out DateTime result)
        {
            return DateTime.TryParse(s, out result);
        }

        public static bool TryParseDateTime(string s, System.Globalization.DateTimeStyles styles, IFormatProvider provider, out DateTime result)
        {
            return DateTime.TryParse(s, provider, styles, out result);
        }

        public static bool TryParseGuid(string s, out Guid guid)
        {
            guid = Guid.Empty;

            try
            {
                guid = new Guid(s);

                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
